#include<iostream>
#include<cstring>
#include<map>
using namespace std;
const int N = 1010;
typedef pair<int, int> PII;
map<char, PII>mp = { {'a',{2,1}},{'b',{3,6}},{'c',{3,4}},{'d',{2,3}},
	{'e',{1,3}},{'f',{2,4}},{'g',{2,5}},{'h',{2,6}},{'i',{1,8}},
	{'j',{2,7}},{'k',{2,8}},{'l',{2,9}},{'m',{3,8}},{'n',{3,7}},
	{'o',{1,9}},{'p',{1,10}},{'q',{1,1}}, {'r',{1,4}},{'s',{2,2}},{'t',{1,5}},
	{'u',{1,7}},{'v',{3,5}},{'w',{1,2}}, {'x',{3,3}},{'y',{1,6}},{'z',{3,2}}
};
bool flag[N];
int main()
{
	int t;
	cin >> t;
	while (t--) {
		string a;
		cin >> a;
		memset(flag, 0, sizeof(flag));
		int n = a.size();
		for (int i = 0; i < n; i++) {
			if (a[i] >= 'A' && a[i] <= 'Z') {
				a[i] += 32;
				flag[i] = 1;
			}
		}
		for (int i = 0; i < n; i++) {
			if (flag[i]) {
				cout << 3 << " " << 1 << " ";
			}
			PII t;
			t = mp[a[i]];
			cout << t.first << " " << t.second;
			cout << endl;
		}
	}
	return 0;
}